// over layer
var g_overLayer;
var OverLayer = cc.Layer.extend({
    ///////////// constructor ///////////////////
    ctor:function () {
        // super init first
        this._super();
        g_overLayer=this;
        // add canvas
        this.addCanvas();
        // add menu
        this.AddMenu();

        this.addTouchEvent();
    },
    onEnter:function () {
        this._super();
    },
    ////////////////////////////////////////////////
    addCanvas : function(){
        var filename = MainResource("over.jpg");
        var background = new cc.Sprite(filename);
        background.setPosition( cc.p(cc.winSize.width/2,cc.winSize.height/2) );
        this.addChild(background);
    },
    AddMenu : function(){
        var filename0 = MainResource("rePlay0.png"),filename1 = MainResource("rePlay1.png");
        var begin = new cc.MenuItemImage(filename0,filename1,this.onRePlaying , this);
        begin.setPosition( cc.p(cc.winSize.width*0.5+20,160) );
        var menu = cc.Menu.create( begin );
        menu.setPosition(cc.p(0,0));
        this.addChild( menu );
    },
    addTouchEvent : function(){
        cc.eventManager.addListener({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: true,
            onTouchBegan: this.onTouchBegan
        }, this );
    },
    ////////////////////////////////////////////////
    onTouchBegan : function (touch, event) {
        var target = event.getCurrentTarget();
        if(target&&target.isVisible()){
            return true;
        }
        return false;
    },
    onRePlaying : function(sender){
        Loading.preload(g_mainRes, function () {
            cc.director.runScene( new MainScene() );
        }, this);
    }
});